<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminRbacTable extends Migration
{
    public function up()
    {
        // role    角色名
        Schema::create('role', function (Blueprint $table) {
            $table->increments('id');
            $table->string('role_name', 50)->unique()->comment('角色名称');

        });
        // permission   权限称
        Schema::create('permission', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 50)->comment('权限名称');
            $table->string('url', 100)->nullable()->comment('页面URL');
            $table->integer('pid')->default(0)->comment('父级ID');
            $table->string('icon', 50)->nullable()->default('')->comment('图标');
            $table->smallInteger('sort')->nullable()->default(50)->comment('排序');

        });
        //  user->role  用户-角色 关系表
        Schema::create('user_role', function (Blueprint $table) {
            $table->integer('user_id')->comment('用户表ID');
            $table->integer('role_id')->comment('角色表ID');

        });
        //    role->permission  角色-权限 关系表
        Schema::create('role_permission', function (Blueprint $table) {
            $table->integer('role_id')->comment('角色表ID');
            $table->integer('permission_id')->comment('权限表ID');
        });
    }

    public function down()
    {
        Schema::dropIfExists('role');
        Schema::dropIfExists('permission');
        Schema::dropIfExists('user_role');
        Schema::dropIfExists('role_permission');
    }


}
